package com.eh.excel;

import com.google.common.collect.Lists;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;

import java.util.List;

/**
 * Created by David Li on 2016/11/24.
 */
public final class PropertiesWriteUtil {
    private static Properties properties;

    static {
        properties = new Properties();
        InputStream in = Object.class.getResourceAsStream("/excel.w.properties");
        try {
            // 解决中文乱码，使用BufferedReader包装
            properties.load(new BufferedReader(new InputStreamReader(in)));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static String getUploadPath(String key) {
        return properties.getProperty(key + ".uploadPath").trim();
    }

    public static String getTableName(String key) {
        return properties.getProperty(key + ".table").trim();
    }

    public static String getSheets(String key) {
        return properties.getProperty(key + ".sheets").trim();
    }

    public static List<String> getColumns(String key) {
        String columnsStr = properties.getProperty(key + ".columns");
        List<String> columns = Lists.newArrayList(columnsStr.split(","));
        return columns;
    }
}
